<?php

/**
 * Created by PhpStorm. User: ADun, Date: 14-10-15 下午10:11
 * Description:
 */
$openId=getCurrentUserOID();

if(empty($openId)) exit('参数错误');
$查看所有病例文章 = $bm->生成有效链接('Seller19BingliAS',$_GET['state']);
$bm = new CUI数据中心(Page::b病历管理,$openId);


$注册 = $bm->生成有效链接('register',$_GET['state']);
$sql = "SELECT   `密码`,`认证`  from `用户`  where id = ".$_SESSION['vo用户数据']['id'];
$个人信息 = pdo()->selectOne($sql);

if($个人信息['密码']=="") {
    echo "<script>alert('请加入爱贝医生才能查看哦');window.location.href= '".$注册."';</script>";
    die;
}

$认证 = $bm->生成有效链接('Seller18ZiLiao',$_GET['state']);
if($个人信息['认证'] == 1 ||!$个人信息['认证'] || $个人信息['认证'] ==''||$个人信息['认证'] ==='') {
    echo "<script>alert('请先加入爱贝医生');window.location.href= '".$认证."';</script>";
    die;
}

$所有可关联人员 = $bm->fc所有可关联人员();
$所有区域 = $bm->fc查找所有区域();
$所有医院 = $bm->fc查找所有医院();

require_once "jssdk.php";
$数据=pdo()->selectColumns('public_serv_accounts',array('AppSecret','app_id'),array('id'=>$_SESSION['vo用户数据']['公众号ID']));
$jssdk = new JSSDK($数据['app_id'], $数据['AppSecret']);
$signPackage = $jssdk->getSignPackage();


#处理提交表单
if(isset($_POST['okn'])){
    if($_REQUEST['title']==''){
        echo "<script>alert('请认真填写信息!');</script>";
    }else{

        $c用户=new C用户($bm->vo信息中心);

        $re= $c用户->ft添加病历文章($_REQUEST);

        $图片路径 = 'cache/BingliAS_img/';

        $图片 = $bm -> 多图上传($_FILES,$图片路径);
        $do=new Do病历文章();
        $do->set_t1($图片[0]);
        $do->set_t2($图片[1]);
        $do->set_t3($图片[2]);
        $do->set_t4($图片[3]);
        $do->set_t5($图片[4]);
        $do->set_id($re);
        $do->update();

        if($re){
            echo "<script>alert('添加病历成功');location.replace(location.href='".$查看所有病例文章."');</script>";
        }else{
            echo "<script>alert('添加病例失败');</script>";
        }

    }

}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no"/>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>发布病例</title>
    <link rel="stylesheet" href="../style/common.css?<?=版本?>">
    <script src="../resource/js/jquery-1.11.1.min.js"></script>
    <script src="//res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="../../app/js/common.js"></script>
</head>
<!-- 配置文件 -->
<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="../ueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">

    function fun() {
        var ue = UE.getEditor('container', {
            toolbars: [
                ['fullscreen', 'source', '|', 'undo', 'redo', '|',
                    'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'pasteplain', '|', 'forecolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                    'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                    'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                    'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'link', 'unlink', 'anchor', '|',
                    'simpleupload', 'emotion']
            ],
            autoHeightEnabled: true,
            autoFloatEnabled: true
        });
    }

    //下面用于图片上传预览功能
    function setImagePreview(avalue) {
        var docObj=document.getElementById("doc"+avalue);

        var imgObjPreview=document.getElementById("preview"+avalue);
        if(docObj.files && docObj.files[0])
        {
//火狐下，直接设img属性
            imgObjPreview.style.display = 'block';
            imgObjPreview.style.width = '44px';
            imgObjPreview.style.height = '44px';
//imgObjPreview.src = docObj.files[0].getAsDataURL();

//火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
            imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
        }
        else
        {
//IE下，使用滤镜
            docObj.select();
            var imgSrc = document.selection.createRange().text;
            var localImagId = document.getElementById("localImag"+avalue);
//必须设置初始大小
            localImagId.style.width = "44px";
            localImagId.style.height = "44px";
//图片异常的捕捉，防止用户修改后缀来伪造图片
            try{
                localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
                localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
            }
            catch(e)
            {
                alert("您上传的图片格式不正确，请重新选择!");
                return false;
            }
            imgObjPreview.style.display = 'none';
            document.selection.empty();
        }
        return true;
    }

    wx.config({
        debug: false,
        appId: '<?php echo $signPackage["appId"];?>',
        timestamp: <?php echo $signPackage["timestamp"];?>,
        nonceStr: '<?php echo $signPackage["nonceStr"];?>',
        signature: '<?php echo $signPackage["signature"];?>',
        jsApiList: [
            'hideMenuItems',
            'hideAllNonBaseMenuItem'
        ]
    });

    wx.ready(function(){
        wx.hideAllNonBaseMenuItem();
    });

</script>
<body onload="fun()">
<form action="" method="post" enctype="multipart/form-data">
<div class="header"><a href="<?= $查看所有病例文章?>"  class="return">返回</a><input  type="submit"  class="btn btn-lg btn-success " name="okn" value="发布" /></div>
<div class="case_creat">
    <div class="line"></div>
    <div class="form_box">
        <div class="txt"><input name="title"    type="text" id="keyword" placeholder="请填写标题，必填项" onFocus="if(value==defaultValue){value='';this.style.color='#000'}" onBlur="if(!value){value=defaultValue;this.style.color='#DB3656'}" /></div>
    </div>
    <div class="line"></div>
    <div class="form_box">
        <div class="txt"><input name="关键词" id="关键词" type="text"   placeholder="病历关键词（多个关键词请用英文逗号隔开）" onFocus="if(value==defaultValue){value='';this.style.color='#000'}" onBlur="if(!value){value=defaultValue;this.style.color='#CCC'}" /></div>
    </div>
    <div class="line"></div>
    <div class="upload_imgs">
        <ul>
            <li><div> <div id="localImag1"><img id="preview1" src="../style/add_img.png" width="44" height="44" style="display: block; width: 44px; height: 44px;"></div><input type="file" id="doc1" onchange="javascript:setImagePreview(1);" name="pic[]" >
                    </div></li>
            <li><div><div id="localImag2"><img id="preview2" src="../style/add_img.png" width="44" height="44" style="display: block; width: 44px; height: 44px;"></div><input type="file" id="doc2" onchange="javascript:setImagePreview(2);" name="pic[]" >
                   </div></li>
            <li><div><div id="localImag3"><img id="preview3" src="../style/add_img.png" width="44" height="44" style="display: block; width: 44px; height: 44px;"></div> <input type="file" id="doc3" onchange="javascript:setImagePreview(3);" name="pic[]">
                   </div></li>
            <li><div><div id="localImag4"><img id="preview4" src="../style/add_img.png" width="44" height="44" style="display: block; width: 44px; height: 44px;"></div><img src="../style/add_img.png" /> <input type="file" id="doc4" onchange="javascript:setImagePreview(4);" name="pic[]">
                   </div></li>
            <li><div><div id="localImag5"><img id="preview5" src="../style/add_img.png" width="44" height="44" style="display: block; width: 44px; height: 44px;"></div><img src="../style/add_img.png" /> <input type="file" id="doc5" onchange="javascript:setImagePreview(5);" name="pic[]"></li>
        </ul>


    </div>
    <div class="line mt10"></div>
    <div class="form_box">
        <div class="txt"><textarea id="container" name="content" placeholder="病例补充说明"></textarea></div>
    </div>
    <div class="line"></div>
    <div class="line mt10"></div>
    <div class="form_box"><select name="区域id" >
            <?php
            foreach($所有区域 as $show){
                echo '<option value="'.$show->data['id'].'" > '.$show->data['区域'].' </option>';} ?>
        </select></div>
    <div class="line"></div>
   <!-- <div class="form_box"> <select name="医院id" >
            <?php
            foreach($所有医院 as $show){
                echo '<option value="'.$show->data['id'].'" > '.$show->data['医院'].' </option>';} ?>
        </select>
        </select></div>
-->
   <div class="form_box"><div class="txt"><input name="医院id" type="text" id="医院id" value="所在医院" onFocus="if(value==defaultValue){value='';this.style.color='#000'}" onBlur="if(!value){value=defaultValue;this.style.color='#DB3656'}" /></div></div>
    <div class="line"></div>
    <!--医生列表 begin-->
<!--    <div class="dr_list">-->
<!--        <div class="dr_list_t">邀请专家回答：</div>-->
<!--        <ul>-->
<!--            --><?php
//            foreach($所有可关联人员 as $show){
//
//                echo '<li><div class="check_box"><input name="专家id[]" type="checkbox" value="'.$show['id'].'" id="'.$show['id'].'" /><label for="'.$show['id'].'"><div>'.$show['显示名称'].' </div></label></div></li>';
//            }
//            ?>
<!---->
<!---->
<!--        </ul>-->
<!--    </div>-->
    <!--医生列表 end-->
</div>
</form>
<div style="width:100%;height:30px;"></div>
<div style="height:30px;width:100%;background:#db3655;color:#fff;font-size:80%;line-height:30px;text-align:center;position:fixed;bottom:0px;">操作过程中如有疑问，请致电客服热线：400-825-8989</div></body>
</body>
</html>
